package escape;

import org.w3c.dom.events.Event;
import org.w3c.dom.events.EventListener;


/**
 * @ProjectName concurrent_study
 * @PackageName escape
 * @ClassName ThisSafe.java
 * @Description TODO
 * @Author yingyuwei
 * @Version 1.0.0
 * @CreateTime 2020年12月01日 21:25:00
 */
public class ThisSafe {
    public final int id;
    public final String name;
    private final EventListener eventListener;

    private ThisSafe() {
        id = 1;
        //内部类是可以直接访问外部类的成员变量的（外部类引用this被内部类获取了）
        eventListener = new EventListener() {
            @Override
            public void handleEvent(Event evt) {
                doSomething(evt);
            }
        };
        name = "flysqrlboy";
    }

    public static void getInstance(EventSource<EventListener> source){
        //先初始化
        ThisSafe obj = new ThisSafe();
        //再发布
        source.registerListener(obj.eventListener);
    }

    public void doSomething(Event e) {
        System.out.println(e);
    }
}
